package cj.hrm.listener;

import cj.hrm.dto.excel.EmployeeToExcel;
import cj.hrm.service.EmployeeExcelService;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: <a href="mailto:get_xiaobo@163.com">Joshxu</a>
 * @description:
 * @create: 2021/5/8 10:00 下午
 **/
public class EmployeeListener extends AnalysisEventListener<EmployeeToExcel> {

    private static final Logger log = LoggerFactory.getLogger(EmployeeListener.class);

    private final EmployeeExcelService employeeExcelService;

    public EmployeeListener(EmployeeExcelService employeeExcelService) {
        this.employeeExcelService = employeeExcelService;
    }

    List<EmployeeToExcel> list = new ArrayList<>();

    @Override
    public void invoke(EmployeeToExcel employeeToExcel, AnalysisContext analysisContext) {

        list.add(employeeToExcel);
        log.info("解析的数据{}",employeeToExcel);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("数据{}",list);
        employeeExcelService.employeeExcelDataToDB(list);
    }
}
